package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.management.mapper.RoleMapper;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: chouh
 * @DateTime: 2025/10/8 19:58
 * @Description:
 */
@Service
@SuppressWarnings("all")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> queryAllRoles() {
        return roleMapper.queryAllRoles();
    }

    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    @Override
    public Role queryRoleById(Integer id) {
        return roleMapper.queryRoleById(id);
    }

    @Override
    public void addRole(Role role) {
        role.setCreateTime(java.time.LocalDateTime.now());
        role.setUpdateTime(java.time.LocalDateTime.now());
        roleMapper.insertRole(role);
    }

    @Override
    public void deleteRole(Integer id) {
        roleMapper.deleteRole(id);
    }

    @Override
    public PageResult<Role> page(String name, String label, Integer page, Integer pageSize) {
            Integer total = roleMapper.count(name, label);
            Integer offset = (page - 1) * pageSize;
            List<Role> rows = roleMapper.selectByPage(name, label, offset, pageSize);
            return PageResult.<Role>builder().total(total).rows(rows).build();
        }
    }

